<?php
class Dice {
    private $quantity;
	private $double = false;
	
    public function __construct($quantity = 1) {
        $this->quantity = $quantity;
    }

    // {{{ roll()
    /**
    * Rolls dice and return the total
    *
    * @return int
    */
    public function roll() {
        $total = 0;
		$this->setDouble(false);
        for ($count = 0; $count < $this->quantity; $count++) {
			$result = $this->getResult();
			if($result == $total)
			{
				$this->setDouble(true);
			}
			else
			{
				$this->setDouble(false);
			}
			$total += $result;
        } 
		
        return $total;
    }
    // }}}
	
	public function getResult()
	{
		return rand(1,6);
	}
	
	public function setDouble($value)
	{
		$this->double = $value;
	}
	
	public function isDouble()
	{
		return $this->double;
	}
}
